package com.cn.wanxi.front;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.CuisineModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.service.CuisineService;
import com.cn.wanxi.service.impl.CuisineServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/cuisine/findAll")
public class CuisineFindAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //       0 乱码处理
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //        1.得到前端传递过来的数据

        //        2.将数据封装到model
     CuisineModel cuisineModel=new CuisineModel();


        //        3.创建服务逻辑层
       CuisineService cuisineService=new CuisineServiceImpl();
        //        4.接收服务逻辑层返回信息

        ResultModel resultModel = cuisineService.findAll(cuisineModel);
        //        5.将信息返回给前端
        resp.getWriter().println(JSONObject.toJSONString(resultModel));
    }
}
